/* import Mock from "mockjs"

// const routes = require('../assets/dynamicRoutes');

// 模拟用户数据
const users = [
    { id: "001", name: "张三" },
    { id: "002", name: "李四" },
    { id: "003", name: "王五" },
    { id: "004", name: "王六" },
    { id: "005", name: "小明" },
    { id: "006", name: "牛粪" },
    { id: "007", name: "大狗" },
    { id: "008", name: "小猫" },
    { id: "009", name: "小猪" },
    { id: "0010", name: "小虎" },
    { id: "0011", name: "小龙" },
    { id: "0013", name: "小兔" },
    { id: "0014", name: "小兔" },
    { id: "0015", name: "小兔" },
    { id: "0016", name: "小兔" },
    { id: "0017", name: "小兔" },
];

const blackList = [
    { id: "0018", name: "小兔" },
]


Mock.mock('/admin/userManage/getUserList', 'post', req => {
    const { keyword, pageNum } = JSON.parse(req.body);
    // this.todos.unshift(item);
    const re = new RegExp(`.*${keyword}.*`);
    const list = users.filter((user) => !user.name.search(re));
    // 按分页截取结果集合
    const result = list.slice((pageNum - 1) * 8, pageNum * 8);
    console.log(list.length)
    console.log('总页数：', Math.ceil(list.length / 8));
    return {
        code: 200,
        data: {
            userList: result,
            pageInfo: {
                // 总页数
                totalPage: Math.ceil(list.length / 8),
                // 当前页码
                // pageNum: ,
            }
        },
        msg: "搜索成功"
    }
})

// 移入黑名单的方法（抽取出来复用）
function blackUserToList(id) {
    users.forEach((user, index) => {
        if (user.id == id) {
            blackList.unshift(users.splice(index, 1)[0]);
        }
    });
}


// 模拟后端将用户移入黑名单接口
Mock.mock('/admin/userManage/blackListUser', 'post', req => {
    const { id } = JSON.parse(req.body);
    blackUserToList(id);
    console.log(blackList);
    return {
        code: 200,
        data: {},
        msg: '已移入黑名单'
    }
})


// 模拟后端批量移入黑名单接口(简单的批量移入操作，不做异常处理)
Mock.mock('/admin/userManage/blackListUsers', 'post', req => {
    // 接收前端传递的用户id数组
    const { idList } = JSON.parse(req.body);
    idList.forEach((id) => blackUserToList(id));
    return {
        code: 200,
        data: {},
        msg: '已移入黑名单'
    }
})

// 返回黑名单数据
Mock.mock("/admin/userManage/blackList", 'get', {
    code: 200,
    data: {
        blackList: blackList,
        pageInfo: {
            // 总页数
            totalPage: Math.ceil(blackList.length / 8),
            // 当前页码
            // pageNum: ,
        }
    },
    msg: '返回黑名单数据'
})

Mock.mock("/admin/userManage/getBlackList", "post", req => {
    const { keyword, pageNum } = JSON.parse(req.body);
    // this.todos.unshift(item);
    const re = new RegExp(`.*${keyword}.*`);
    const list = blackList.filter((user) => !user.name.search(re));
    // 按分页截取结果集合
    const result = list.slice((pageNum - 1) * 8, pageNum * 8);
    console.log(list.length)
    console.log('总页数：', Math.ceil(list.length / 8));
    return {
        code: 200,
        data: {
            blackList: result,
            pageInfo: {
                // 总页数
                totalPage: Math.ceil(list.length / 8),
                // 当前页码
                // pageNum: ,
            }
        },
        msg: "搜索成功"
    }
})

// 将一个用户移出黑名单（方法抽取出来可复用）
function cancelBlackList(id) {
    blackList.forEach((user, index) => {
        if (user.id == id) {
            users.unshift(blackList.splice(index, 1)[0]);
        }
    });
}

// 移出黑名单
Mock.mock("/admin/userManage/cancelBlackListUser", "post", req => {
    const { id } = JSON.parse(req.body);
    cancelBlackList(id);
    console.log(blackList);
    return {
        code: 200,
        data: {},
        msg: '已移入黑名单'
    }
})

// 批量移出黑名单
Mock.mock("/admin/userManage/cancelBlackListUsers", "post", req => {
    const { idList } = JSON.parse(req.body);
    idList.forEach((id) => cancelBlackList(id));
    return {
        code: 200,
        data: {},
        msg: '已移入黑名单'
    }
})

export default {
} */